package JsonProcess;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import Storage.Message;

public class jAllMessages { // Parse JsonString
	public static ArrayList<Message> process(String jsonText)
			throws JSONException {
		ArrayList<Message> messagelist = new ArrayList<Message>();
		JSONArray array = new JSONArray(jsonText);
		
		for (int i = 0; i < array.length(); i++) {
			Message msg = new Message();
			JSONObject object;
			object = (JSONObject) new JSONTokener(array.getString(i))
					.nextValue();
			msg.setMsgId(object.getString("msgid"));
			msg.setSenderName(object.getString("sendername"));
			msg.SetMsgContent(object.getString("msgcontent"));
			msg.setTime(object.getString("time"));
			
			messagelist.add(msg);
		}
		return messagelist;
	}

}
